package com.lgc.javathread.chapter1.t4_threadsafe;

public class LoginServlet {
    private static String usernameRef; //静态变量，全局仅一份
    private static String passwordRef;

    //解决这个非线程安全的方法也使用synchronized关键字
    synchronized public static void doPost(String username,String password)
    {
        try
        {
            usernameRef = username;
            if(username.equals("a")){
                Thread.sleep(5000);
            }

            passwordRef = password;
            System.out.println("username="+usernameRef+"&password="+passwordRef);
        }catch (InterruptedException e){
            e.printStackTrace();
        }
    }
}
